package com.isay.frameworklib.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by cywu4 on 2018/8/6.
 */

public abstract class BaseFragment extends Fragment {


    protected Context mContext;

    protected View mRootView = null;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (mRootView == null) {
            mContext = getContext();
            mRootView = inflater.inflate(getLayoutId(), container, false);
            initView(mRootView);
            initData();
        }
        return mRootView;
    }

    /**
     * 创建rootView: inflater.inflate(R.layout.fragment_main, container, false);
     */
    protected abstract int getLayoutId();

    /**
     * 初始化view,除了recyclerView和smartRefreshLayout
     */
    protected abstract void initView(View rootView);


    /**
     * 初始化数据，比如初始化执行网络请求
     */
    protected abstract void initData();


}
